<?php
// +----------------------------------------------------------------------
// | Author: sam <yimingsha@qq.com>
// +----------------------------------------------------------------------
namespace Sam;

class Factory {
	static function createMember(){
		$key='Member';
		$Obj = Register::get($key);
		if( !$Obj ){
			$Obj = new Member();
			Register::set($key,$Obj);
		}

		return $Obj;
	}


	static function createAccount(){
		$key='Account';
		$Obj = Register::get($key);
		if( !$Obj ){
			$Obj = new Account();
			Register::set($key,$Obj);
		}

		return $Obj;
	}

	static function createSMS($type){
		$key = 'SMS'.'_'.$type;
		$Obj = Register::get($key);
		if( !$Obj ){
			$Obj = new SMS($type);
			Register::set($key,$Obj);
		}
		return $Obj;
	}

	static function sms_send($phone,$message){
        $result = self::createSMS('ali')->send($phone,$message);
        return $result;

	}


	//生成验证码
	static function initMsgVerifyCode(){
		$code = mt_rand(100000, 999999);
		return $code;
	}


	static function createMessage(){
		$key = 'Message';
		$Obj = Register::get($key);
		if( !$Obj ){
			$Obj = new Message();
			Register::set($key,$Obj);
		}
		return $Obj;
	}
	static function createSnoopy()
	{
		$key = 'Snoopy';
		$Obj = Register::get($key);
		if (!$Obj) {
			$Obj = new Snoopy();
			Register::set($key, $Obj);
		}
		return $Obj;
	}


	//来源标签
	static function sourceLabel($label='',$glue=''){
		$key = 'sourceLabel';
		$arr = Register::get($key);
		if( !$arr ){
			$arr = array();
		}

		if($label && !in_array($label,$arr) ){
			$arr[] = $label;
			Register::set($key,$arr);
		}
		if( $glue!='' ){
			return implode($glue,$arr);
		}
		return $arr;
	}
}